{include file='public/header' /}
    <style>
        .layui-form-label{width: 140px}
        .layui-input-inline{}
        .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
        .header div{border-bottom: solid 2px #009688;margin: 8px 0 6px 0;}
        .header button{float: right;margin-top: -5px;}
    </style>
</head>
<body style="padding: 10px;">
<div class="header">
    <span>业务员</span>
    <div></div>
</div>
<form class="layui-form">
    <input type="hidden" name="id" value="{$sales.id}">
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span>业务员名称</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="truename">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span>联系电话:</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="phone">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span>密&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码</label>
        <div class="layui-input-inline">
            <input type="password" class="layui-input" name="password">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722">*</span>密&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码</label>
        <div class="layui-input-inline">
            <input type="password" class="layui-input" name="password2">
        </div>
    </div>
</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" onclick="save()">保存</button>
    </div>
</div>

<script type="text/javascript">
    layui.use(['layer','form'],function(){
        form = layui.form;
        layer = layui.layer;
        $ = layui.jquery;
        $('input[name="truename"]').val('{$sales.truename}');
        $('input[name="phone"]').val('{$sales.phone}');
    });

    // 保存管理员
    function save(){
        var truename = $.trim($('input[name="truename"]').val());
        var phone = $.trim($('input[name="phone"]').val());
        var password = $.trim($('input[name="password"]').val());
        var password2 = $.trim($('input[name="password2"]').val());
        var id = $('input[name="id"]').val();
        //alert(id);
        if(truename==''){
            layer.alert('请输入业务员名称',{icon:2});
            return;
        }
        if(phone==''){
            layer.alert('请输入手机号',{icon:2});
            return;
        }
        if(password!=password2){
            layer.alert('两次密码输入不一致',{icon:2});
            return;
        }
        //.serialize()是将表单中的值序列化id=0&username=2&gid=1&pwd=2&truename=2
        $.post('__PUBLIC__/admin/sales/save',$('form').serialize(),function(res){
            console.log(res);
            if(res.code>0){
                layer.alert(res.msg,{icon:2});
            }else{
                layer.msg(res.msg);
                setTimeout(function(){window.location.reload();},1000);
                //setTimeout(function(){parent.window.location.reload();},1000);
            }
        },'json');
    }

</script>
</body>
</html>